< previous page page_417 next page >

Page 417
' Collection of ServiceObject objects that are currently
' being changed
Dim ChangesInProgress As Collection

Dim Changed As Boolean  ' Mark true if any state change has been caused
Dim unloadpending As Boolean    ' Mark true if final restore operation

' 0 to restore
Dim TargetState As ServiceStateConstants
The ServiceManager object is initialized when the main form loads. At that time, the OriginalStates collection is loaded with the original running state of each service:
Private Sub Form_Load()
    Dim res&
    ' Open the ServiceManager
    res = sc.OpenSCManager("", "", SC_MANAGER_ENUMERATE_SERVICE _
    Or SC_MANAGER_CONNECT)
    ' Update the ServiceCollection and display the services
    LoadList True
    Set OriginalStates = ServiceCollection
    ' We don't want to hold two references to the collection
    Set ServiceCollection = Nothing
End Sub
The ServiceCollection collection is loaded using the LoadList function. This function makes use of the ServiceManger object's EnumServicesStatus method to obtain the names and status of the available services. The ServiceManager object (referenced by the sc variable) is initialized when the form loads:
' Loads the ServiceCollection collection with a list of all services
' Optionally displays them
Private Sub LoadList(bDisplay As Boolean)
    Dim res&
    Dim svcstat As ServiceStatus
    lstServices.Refresh
    Set ServiceCollection = sc.EnumServicesStatus()
    If bDisplay Then
        For Each svcstat In ServiceCollection
            lstServices.AddItem svcstat.Name & ":   " & svcstat.DisplayName
        Next
    End If

 
< previous page page_417 next page >